use precompiled headers to speed up compile time (#851)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 18 Feb 2022 18:04:01 +0000 (11:04 -0700)
committerGitHub <noreply@github.com>
Fri, 18 Feb 2022 18:04:01 +0000 (11:04 -0700)
* speed up compiles with precompiled headers.

* workaround QTBUG with precompiled headers and clang.

* avoid including QtCore.

* add ability to turn off precompiled headers.

.gitignore
CMakeLists.txt
GPSBabel.pro
mynav.cc
precompiled_headers.h [new file with mode: 0644]
src/core/codecdevice.cc
src/core/codecdevice.h
src/core/textstream.cc

index 957c3cac4b2f6b3d2a2e848af0c3fa70e49873b5..096b82de5da17fe3fadafb0595ddbb56fa85d818 100644 (file)
@@ -36,6 +36,7 @@ CMakeFiles/
 *.swp
 /tmp/
 /mkcapabilities
+/gpsbabel.gch/
 /gpsbabel.rc
 /autogen/
 /makedoc
index 7dcb4d4a9a6f682e0b9b67639c3ca64548741409..d0acd5774546273c009d5da89fe14f5605b1abf8 100644 (file)
@@ -39,6 +39,29 @@ if(${QT_VERSION_MAJOR} EQUAL "6")
   list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Core5Compat)
 endif()
 
+option(GPSBABEL_ENABLE_PCH "enable precompiled headers." ON)
+if (GPSBABEL_ENABLE_PCH)
+  target_precompile_headers(gpsbabel PRIVATE
+    "$<$<COMPILE_LANGUAGE:CXX>:<algorithm$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<cmath$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<cstdarg$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<cstdint$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<cstdio$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<ctime$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<optional$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<utility$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QDebug$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QList$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QScopedPointer$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QString$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QTextCodec$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QVector$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<Qt$<ANGLE-R>>"
+    "$<$<COMPILE_LANGUAGE:CXX>:<QtGlobal$<ANGLE-R>>"
+  )
+endif()
+
 # RESOURCES
 set(RESOURCES gpsbabel.qrc)
 
index 49faaaf012719d429009dce10ecd85dceb72a0c3..47b2be048ee898941cbcdeda877c1941231547e3 100644 (file)
@@ -26,6 +26,15 @@ CONFIG += console
 CONFIG -= app_bundle
 CONFIG += c++17
 CONFIG += link_pkgconfig
+!disable_pch {
+  # avoid QTBUG-72404, QTBUG-79694 which were fixed in 5.14.0
+  versionAtLeast(QT_VERSION, 5.14.0) | !contains(QMAKE_CXX, .*clang.*) {
+    CONFIG += precompile_header
+    PRECOMPILED_HEADER = precompiled_headers.h
+  } else {
+    message("Not using precompiled headers due to QTBUG.")
+  }
+}
 
 TEMPLATE = app
 
index f2fbf982ead1dd5807fd2cabe986cb86e37772d6..5fbe9b902877cf774806e167f5a7287a6b103e12 100644 (file)
--- a/mynav.cc
+++ b/mynav.cc
@@ -30,7 +30,7 @@
 #include <QStringList>
 #include <QtGlobal>
 
-#include <src/core/textstream.h>
+#include "src/core/textstream.h"
 
 #include "mynav.h"
 
diff --git a/precompiled_headers.h b/precompiled_headers.h
new file mode 100644 (file)
index 0000000..47705c8
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+    Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+
+// This list is from defs.h.  Adding other commonly used headers doesn't help.
+
+#if defined __cplusplus
+#include <algorithm>              // for sort, stable_sort
+#include <cmath>                  // for M_PI
+#include <cstdarg>                // for va_list
+#include <cstddef>                // for NULL, nullptr_t, size_t
+#include <cstdint>                // for int32_t, uint32_t
+#include <cstdio>                 // for NULL, fprintf, FILE, stdout
+#include <ctime>                  // for time_t
+#include <optional>               // for optional
+#include <utility>                // for move
+
+#include <QDebug>                 // for QDebug
+#include <QList>                  // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator
+#include <QScopedPointer>         // for QScopedPointer
+#include <QString>                // for QString
+#include <QTextCodec>             // for QTextCodec
+#include <QVector>                // for QVector
+#include <Qt>                     // for CaseInsensitive
+#include <QtGlobal>               // for foreach
+#endif
index 13290d014704c8de648247216ca4d40a16854871..77e322e45bfd7c1a5707179833de019bdf11b5b2 100644 (file)
 
  */
 
+#include <cassert>     // for assert
 #include <cstring>     // for memcpy
 #include <algorithm>   // for min
 
 #include <QByteArray>  // for QByteArray
 #include <QChar>       // for QChar
-#include <QFile>       // for QFile
 #include <QFlags>      // for QFlags
 
 #include "defs.h"      // for list_codecs, warning
index 320d9aa90ac08d063a2faa3df8e0ba1a2b80e8f3..6ccb7e8acd0718e2b644ec0effe5ed5913799280 100644 (file)
  */
 
 #include <QIODevice>        // for QIODevice
+#include <QIODeviceBase>    // for QIODeviceBase::OpenMode
 #include <QString>          // for QString
 #include <QTextCodec>       // for QTextCodec
 #include <QTextDecoder>     // for QTextDecoder
 #include <QTextEncoder>     // for QTextEncoder
-#include <QtCore>           // for qint64, QIODeviceBase::OpenMode
+#include <QtGlobal>         // for qint64
 
 #include "src/core/file.h"  // for File
 
index 49c10ba88324bfe6e024a00b47f2da382cb80869..2b6f1140e55d139ee33cd8b9e233bb71900e40b5 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 
-#include <QtCore>            // for qint64, QT_VERSION, QT_VERSION_CHECK
+#include <QtGlobal>          // for qint64, QT_VERSION, QT_VERSION_CHECK
 
 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
 #include <QByteArrayView>    // for QByteArrayView